package cn.tedu.weibo.service.impl;

import cn.tedu.weibo.mapper.WeiboMapper;
import cn.tedu.weibo.pojo.dto.WeiboDTO;
import cn.tedu.weibo.pojo.entity.Weibo;
import cn.tedu.weibo.pojo.vo.WeiboDetailVO;
import cn.tedu.weibo.pojo.vo.WeiboIndexVO;
import cn.tedu.weibo.service.IWeiboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WeiboService implements IWeiboService {

    @Autowired
    private WeiboMapper weiboMapper;

    @Override
    public void addNew(WeiboDTO weiboDTO) {
        Weibo weibo = new Weibo();
        BeanUtils.copyProperties(weiboDTO,weibo);
        weibo.setCreated(new Date());
        System.out.println("------------"+weibo);
        weiboMapper.insertWeibo(weibo);
    }

    @Override
    public WeiboDetailVO selectById(Long id) {
        WeiboDetailVO weiboDetailVO = weiboMapper.selectById(id);
        return weiboDetailVO;
    }

    @Override
    public List<WeiboIndexVO> listForIndex() {
        List<WeiboIndexVO> weiboIndexVOS = weiboMapper.selectForIndex();
        return weiboIndexVOS;
    }
}
